<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Weixin\Controller;
use User\Api\UserApi;


class MemberController extends WeixinController {

    protected function _initialize(){
        require_once('ThinkPHP/Library/Vendor/api_payment/llpaypayment.php');
        require_once('ThinkPHP/Library/Vendor/OCR_API.php');


        /* 读取站点配置 */
        $config = api('Config/lists');
        C($config); //添加配置
        if(!C('WEB_SITE_CLOSE')){
            $this->error('站点已经关闭，请稍后访问~');
        }
        $options = array(
            'token'     => $this->token,   // 填写你设定的key
            'appid'     => $this->appid,    // 填写高级调用功能的appid
            'appsecret' => $this->appsecret // 填写高级调用功能的密钥
        );
        $this->weixin = new \Common\Extend\Wechat\Wechat($options);
        $weixin = cookie('WeixinLogin');
        if(empty($weixin)){
            $this->oauth();
        }else{
            $this->uid          = $weixin['uid'];
            $this->access_token = $weixin['access_token'];
            $this->openid       = $weixin['openid'];
        }
        $where['id'] =$this->uid;
        $count = D('ucenter_member')->where($where)->getField('mobile');
        if(empty($count)){
            $this->redirect('User/mobile');
        }
        
    }



	/* 用户中心首页 */
	public function index(){
		
	}


    public function userinfo(){

        $model = M('Member');
        if(IS_POST){
            // print_r(I('post.'));die;
            $error = D('Loan')->tishi($this->uid);  //查看是否还有借款
            if($error['status']==false){
                print_r('您正处于借款状态,无法修改信息');die;
            }
            

            $form = I('post.member');    
            if(empty($form['reside_addr'])){
                print_r('请输入您的现居住地址');die;
            }
            if($form['reside_duration']==0){
                print_r('请选择您的居住时长');die;
            }
            if(empty($form['marital_status'])){
                print_r('请选择您的婚姻状态');die;
            }
            if(empty($form['unitname'])){
                print_r('请输入您的单位名称');die;
            }
            if(empty($form['career_type'])){
                print_r('请选择您的职业类型');die;
            }
            if(empty($form['unit_addr'])){
                print_r('请输入您的单位地址');die;
            }
            if(empty($form['unit_phone'])){
                print_r('请输入您的单位电话');die;
            }
            if($form['relati_onship']==0){
                print_r('请选择您的直系亲属');die;
            }
            if($form['social_relations']==0){
                print_r('请选择您的社会关系');die;
            }

            if(empty($form['relati_name'])){
                print_r('请输入亲属姓名');die;
            }
            if(empty($form['social_name'])){
                print_r('请输入好友姓名');die;
            }

            if(empty($form['social_number'])){
                print_r('请输入好友电话');die;
            }
            if(empty($form['social_number'])){
                print_r('请输入亲属电话');die;
            }
            
            $trl = $model->where("uid={$this->uid}")->save($form);

            if($trl){
                print_r('修改资料成功！');die;
                // $this->success('操作成功',U('Index/index'));
            }else{
                // $this->error('操作失败');
                print_r('修改资料失败！');die;
            }
        }else{
            $info  = $model->where("uid={$this->uid}")->find();
            $this->assign('info',$info);
            C('WEB_SITE_TITLE','基本信息');
            $this->display();
        }
    }
}
